﻿var addTabs = function(tabPanel, xmlString) {

    var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
    xmlDoc.loadXML(xmlString);
    var nodes = xmlDoc.selectNodes("root/tab");
    for (var i = 0; i < nodes.length; i++) {
        addTab(tabPanel, nodes[i].getAttribute("id"), nodes[i].getAttribute("name"), nodes[i].getAttribute("url"));
    }
    if (xmlString != "") {
        var tab = tabPanel.getComponent(nodes[0].getAttribute("id"));
        tabPanel.setActiveTab(tab);
    }
}

function addTab(tabPanel, id, name, url) {
    var tab = tabPanel.getComponent(id);
    if (!tab) {
        tab = tabPanel.add({
            id: id,
            title: name,            
            closable: true,
            autoLoad: {
                showMask: true,
                nocache: true,
                url: url,
                mode: 'iframe',
                maskMsg: '加载 ' + name + '...'
            }
        });
    }
}

/*----paramStr可省略-----*/
var addTabs1 = function(tabPanel, xmlString, param,paramStr) {
	if (tabPanel.items.items.length > 0) {
		for (var i = tabPanel.items.items.length; i >= 1; i--) {
			tabPanel.closeTab(tabPanel.items.items[i]);
		}
	}
	var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
	xmlDoc.loadXML(xmlString);
	var nodes = xmlDoc.selectNodes("root/tab");

	for (var i = 0; i < nodes.length; i++) {
		var url = nodes[i].getAttribute("url");
		var paramTip = url.indexOf("?") >= 0? "&":"?";		
		addTab(tabPanel, nodes[i].getAttribute("id"), nodes[i].getAttribute("name"), url + paramTip+"param=" + param+"&"+paramStr);
	}
	if (xmlString != "") {
		var tab = tabPanel.getComponent(nodes[0].getAttribute("id"));
		tabPanel.setActiveTab(tab);
	}
}

function addTabAndSet(tabPanel, id, name, url) {
    addTab(tabPanel, id, name, url);
    setActiveTab(tabPanel, id);
}

function setActiveTab(tabPanel,id) {
    var tab = tabPanel.getComponent(id);
    tabPanel.setActiveTab(tab);
}

function RedirectExchangeURL(exchangeURL, userName, password) {
//    exchangeURL = "https://10.40.229.147/owa";
    var xmlRequest = new ActiveXObject("MSXML2.XMLHTTP");
    xmlRequest.open("get", exchangeURL, false, userName, password);
    auth = xmlRequest;
    auth.send();
    switch (auth.status) {
        case 200:
            window.location.href = exchangeURL;
            break;
        case 401:
            alert("Invalid user or password。");
            break;
        default:
            alert("Sorry, Exchange Server is busy, please try later!");
    }
}

//为数组添加移除方法
Array.prototype.baoremove = function(dx) 
{ 
    if(isNaN(dx)||dx>this.length){return false;} 
    this.splice(dx,1); 
}